package suanfa;

public class Inthuanfen {
    static int a = 5;

    public static void main(String[] args) {

        System.out.println(hua(a, a));
        System.out.println();
        print(0,0,a);
    }

    private static int hua(int n, int m) {
        if (n == 1 || m == 1)
            return 1;
        else if (n < m)
            return hua(n, n);
        else if (n == m)
            return 1 + hua(n, n - 1);
        else
            return hua(n, m - 1) + hua(n - m, m);
    }

    //输出划分的所有情况
    static int[] mark = new int[200];

    private static void print(int sum, int k, int prio) {
        if (sum > a)
            return;
        if (sum == a) {
            int i;
            for (i = 0; i < k - 1; i++)
                System.out.print(mark[i] + "+");
            System.out.print(mark[i] + "\n");
        } else {
            for (int j = prio; j > 0; j--) {
                mark[k] = j;
                sum += j;
                print(sum, k + 1, j);//递归调用
                sum -= j;//恢复现场
            }
        }
    }

}
